package config

import (
	"github.com/go-ini/ini"
	"matcher/pkg/boot/logger"
	"os"
	"path/filepath"
	"strings"
)

var (
	ROOT_PATH string
	configure *ini.File
	Symbols   []string
)

var (
	EnvConfig = &struct {
		Port string `ini:"port"`
	}{}

	AppConfig = &struct {
		Symbols string `ini:"symbols"`
	}{}
)

func Initialize() {
	var dir, err = filepath.Abs(filepath.Dir(os.Args[0]))
	logger.CatchFatal(err)
	ROOT_PATH = dir

	file, err := ini.Load(ROOT_PATH + "/conf/app.ini")
	logger.CatchFatal(err)
	configure = file
	bind()
}

func bind() {
	logger.CatchFatal(configure.Section("env").MapTo(EnvConfig))

	logger.CatchFatal(configure.Section("app").MapTo(AppConfig))
	Symbols = strings.Split(AppConfig.Symbols, ",")
}
